package kyssion.leetcode.util;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    public static ListNode createListNode(int[] arr) {
        if (arr.length == 0) {
            return null;
        }
        ListNode head = new ListNode(arr[0]);
        ListNode befor = head;
        for (int a = 1; a < arr.length; a++) {
            ListNode node = new ListNode(arr[a]);
            head.next = node;
            head = node;
        }
        return befor;
    }

    public static List<Integer> createArr(ListNode head) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        while (head != null) {
            arrayList.add(head.val);
            head = head.next;
        }
        return arrayList;
    }

    public static void showListNode(ListNode head) {
        while (head != null) {
            System.out.println(head.val + " ");
            head = head.next;
        }
    }

    public static int[] createArray(int length) {
        int[] a = new int[10];
        for (int b = 0; b < a.length; b++) {
            a[b] = (int) (Math.random() * 1000);
        }
        Arrays.sort(a);
        return a;
    }
}
